package com.alinesno.cloud.initializr.starter.service.impl;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alinesno.cloud.common.core.service.impl.IBaseServiceImpl;
import com.alinesno.cloud.common.facade.wrapper.LambadaRpcWrapper;
import com.alinesno.cloud.initializr.starter.entity.InitializrBootVersionEntity;
import com.alinesno.cloud.initializr.starter.repository.InitializrBootVersionRepository;
import com.alinesno.cloud.initializr.starter.service.IInitializrBootVersionService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-11-20 10:06:08
 */
@Service
public class InitializrBootVersionServiceImpl
		extends IBaseServiceImpl<InitializrBootVersionEntity, InitializrBootVersionRepository>
		implements IInitializrBootVersionService {

	// 日志记录
	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(InitializrBootVersionServiceImpl.class);

	@Override
	public Collection<InitializrBootVersionEntity> findByWrapper(
			LambadaRpcWrapper<InitializrBootVersionEntity> rpcWrapper) {
		return mapper.selectList(rpcWrapper.toQueryWrapper());
	}

	@Override
	public boolean save(InitializrBootVersionEntity entity) {
		final int activeDefault = 1;
		if (activeDefault == entity.getIsActive()) {
			mapper.reverseDefaultActive();
		}
		return super.save(entity);
	}

	@Override
	public void update(InitializrBootVersionEntity entity) {
		final int activeDefault = 1;
		if (activeDefault == entity.getIsActive()) {
			mapper.reverseDefaultActive();
		}
		super.update(entity);
	}
}
